package me.boot.auth.spring.model;

import com.google.common.collect.Sets;
import lombok.Data;
import me.boot.sys.entity.SysRole;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Set;
import java.util.stream.Collectors;

@Data
public class SpringUser implements UserDetails {

    private Long id;
    private String name;
    private String username;
    private String password;
    private boolean accountNonExpired;
    private boolean accountNonLocked;
    private boolean credentialsNonExpired;
    private boolean enabled;
    private Set<SysRole> roles = Sets.newHashSet();


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return roles.stream().map(role -> new SimpleGrantedAuthority(role.getName())).collect(Collectors.toList());
    }

    public Collection<SysRole> getRolesByResource(String resource){
        return null;
    }
}
